import { request, METHOD } from '@/utils/request'
import axios from 'axios'

import Cookie from 'js-cookie'

const BASE_URL = process.env.VUE_APP_API_URL
// 设备管理分页查询
export async function deviceManamentList (params) {
  return request(`${BASE_URL}/business/admin/deviceInfo`, METHOD.GET, params)
}
// 设备型号列表
export async function deviceList (params) {
  return request(`${BASE_URL}/business/admin/deviceModelInfo/listNoPage`, METHOD.GET, params)
}
// 获取单个设备
export async function deviceDetail (id) {
  return request(`${BASE_URL}/business/admin/deviceInfo/${id}`, METHOD.GET)
}
// 删除设备
export async function deleteDetail (id) {
  return request(`${BASE_URL}/business/admin/deviceInfo/${id}`, METHOD.DELETE)
}
// 新增设备
export async function addDeviceDetail (params) {
  return request(`${BASE_URL}/business/admin/deviceInfo`, METHOD.POST, params)
}
// 新增设备模板
export async function deviceExcel () {
  const queryParams = {
    Authorization: Cookie.get('Authorization')
  }
  Object.assign(queryParams)
  return axios({
    method: 'get',
    url: `${BASE_URL}/business/admin/deviceInfo/getDeviceExcelTemplate`,
    responseType: 'blob'
  })
}
// 运营管理-车架号-获取车架号导入模板
export async function getVinNoExcelTemplate () {
  const queryParams = {
    Authorization: Cookie.get('Authorization')
  }
  Object.assign(queryParams)
  return axios({
    method: 'get',
    url: `${BASE_URL}/business/admin/vehicleShelfInfo/getVinNoExcelTemplate`,
    responseType: 'blob'
  })
}

// 导入设备
export async function importDevice (params) {
  return request(`${BASE_URL}/business/admin/deviceInfo/uploadDeviceByExcel`, METHOD.POST, params)
}

// 车控关联管理-记录统计-车架号批量撤回
export async function withdrawSomeVnNo (batchNo) {
  return request(`${BASE_URL}/business/admin/vehicleControl/statisticalRecord/batchCancelVinNo/${batchNo}`, METHOD.DELETE)
}
// 车控关联管理-记录统计-设备号批量撤回
export async function withdrawSomeDeviceNo (batchNo) {
  return request(`${BASE_URL}/business/admin/vehicleControl/statisticalRecord/batchCancelDeviceNo/${batchNo}`, METHOD.DELETE)
}
// 物联网卡启停
export async function stopOpenLotCard (id) {
  return request(`${BASE_URL}/business/admin/simManualConfig/changeStatus/${id}`, METHOD.PUT)
}
// 设备定位轨迹1.6.9
export async function deviceLocation (id) {
  return request(`${BASE_URL}/business/admin/deviceInfo/getLatestPosition/${id}`, METHOD.GET)
}
// 设备轨迹信息1.6.9
export async function deviceLocationList (data) {
  return request(`${BASE_URL}/business/admin/deviceInfo/position`, METHOD.GET, data)
}
// 设备库管理列表 1.7.0
export async function deviceStoreList (data) {
  return request(`${BASE_URL}/business/admin/deviceLibrary`, METHOD.GET, data)
}
// 设备库管理新增1.7.0
export async function addDeviceStore (params) {
  return request(`${BASE_URL}/business/admin/deviceLibrary`, METHOD.POST, params)
}
// 设备库管理查看1.7.0
export async function deviceStoreDetail (id) {
  return request(`${BASE_URL}/business/admin/deviceLibrary/${id}`, METHOD.GET)
}

// 设备库管理修改1.7.0
export async function deviceStoreEdit (id, data) {
  return request(`${BASE_URL}/business/admin/deviceLibrary/update/${id}`, METHOD.PUT, data)
}
// 设备库变更记录1.7.0
export async function deviceStoreChangeLog (data) {
  return request(`${BASE_URL}/business/admin/deviceChangeRecord/noPageList`, METHOD.GET, data)
}
// 设备库导出1.7.0
export async function deviceStoreExport (params) {
  // alert(data)
  const queryParams = {
    Authorization: Cookie.get('Authorization')
  }
  Object.assign(queryParams)
  return axios({
    method: 'get',
    url: `${BASE_URL}/business/admin/deviceLibrary/export`,
    responseType: 'blob',
    params
  })
}
// 设备库导入模板1.7.0
export async function getDeviceExcelTemplate () {
  const queryParams = {
    Authorization: Cookie.get('Authorization')
  }
  Object.assign(queryParams)
  return axios({
    method: 'get',
    url: `${BASE_URL}/business/admin/deviceLibrary/getDeviceExcelTemplate`,
    responseType: 'blob'
  })
}
// 设备库导入
export async function importDeviceStore (params) {
  return request(`${BASE_URL}/business/admin/deviceLibrary/uploadDeviceByExcel`, METHOD.POST, params)
}

// YXB 售后-离线数据-获取离线数据
export async function getOffline (data) {
  return request(`${BASE_URL}/business/iotadmin/afterSale/getOffline`, METHOD.GET, data)
}

// 设备-设备管理-查询设备状态-列表查询 WYJ  1.7.2
export async function vehicleCommand (data) {
  return request(`${BASE_URL}/control/admin/vehicleCommand`, METHOD.GET, data)
}

// 设备-设备管理-查询设备状态-查询状态指令发送 WYJ  1.7.2
export async function sendVehicleCommand (deviceNo) {
  return request(`${BASE_URL}/control/admin/vehicleCommand/${deviceNo}`, METHOD.GET)
}
// 新增学生信息
export async function addStudent (params) {
  return request(`${BASE_URL}/students/addStudent`, METHOD.POST, params)
}
